﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Services;
using Entities;
using WebUI.Models;

namespace WebUI.Controllers
{
    public partial class ReportsController : Controller
    {
        #region Member Variables

        readonly IGenericFilesService filesService;
        readonly FilterOperations filter;

        #endregion

        #region Constructor

        public ReportsController(IGenericFilesService filesService, FilterOperations filter)
        {
            this.filesService = filesService;
            this.filter = filter;
        }

        #endregion

        #region Action Methods

        public virtual ViewResult Overview()
        {
            ViewBag.Name = Resources.OverviewTitle;
            return View();
        }

        [ActionName("Reads")]
        public virtual ViewResult ReadsIndex()
        {
            filter.operationType = OperationType.Read;
            var model = new FilesModel(filter);
            model.FilesList = filesService.SearchFileActions(filter);
            ViewBag.Name = Resources.ReadsTitle;
            return View(model);
        }

        [HttpPost]
        [ActionName("Reads")]
        public virtual PartialViewResult FilterReads(FormCollection formCollection)
        {
            filter.operationType = OperationType.Read;
            Common.PopulateFilter(formCollection, filter);
            var results = filesService.SearchFileActions(filter);
            return PartialView(MVC.Reports.Views._ReadsGrid, results);
        }

        [ActionName("Renames")]
        public virtual ViewResult RenamesIndex()
        {
            filter.operationType = OperationType.Rename;
            var model = new FilesModel(filter);
            model.FilesList = filesService.SearchFileActions(filter);
            ViewBag.Name = Resources.RenamesTitle;
            return View(model);
        }

        [HttpPost]
        [ActionName("Renames")]
        public virtual PartialViewResult FilterRenames(FormCollection formCollection)
        {
            filter.operationType = OperationType.Rename;
            Common.PopulateFilter(formCollection, filter);
            var results = filesService.SearchFileActions(filter);
            return PartialView(MVC.Reports.Views._RenamesGrid, results);
        }

        [ActionName("Writes")]
        public virtual ViewResult WritesIndex()
        {
            filter.operationType = OperationType.Write;
            var model = new FilesModel(filter);
            model.FilesList = filesService.SearchFileActions(filter);
            ViewBag.Name = Resources.WritesTitle;
            return View(model);
        }

        [HttpPost]
        [ActionName("Writes")]
        public virtual PartialViewResult FilterWrites(FormCollection formCollection)
        {
            filter.operationType = OperationType.Write;
            Common.PopulateFilter(formCollection, filter);
            var results = filesService.SearchFileActions(filter);
            return PartialView(MVC.Reports.Views._WritesGrid, results);
        }

        [ActionName("Deletes")]
        public virtual ViewResult DeletesIndex()
        {
            filter.operationType = OperationType.Deleted;
            var model = new FilesModel(filter);
            model.FilesList = filesService.SearchFileActions(filter);
            ViewBag.Name = Resources.DeletesTitle;
            return View(model);
        }

        [HttpPost]
        [ActionName("Deletes")]
        public virtual PartialViewResult FilterDeletes(FormCollection formCollection)
        {
            filter.operationType = OperationType.Deleted;
            Common.PopulateFilter(formCollection, filter);
            var results = filesService.SearchFileActions(filter);
            return PartialView(MVC.Reports.Views._DeletesGrid, results);
        }

        [ActionName("Moves")]
        public virtual ViewResult MovesIndex()
        {
            filter.operationType = OperationType.Move;
            var model = new FilesModel(filter);
            model.FilesList = filesService.SearchFileActions(filter);
            ViewBag.Name = Resources.MovesTitle;
            return View(model);
        }

        [HttpPost]
        [ActionName("Moves")]
        public virtual PartialViewResult FilterMoves(FormCollection formCollection)
        {
            filter.operationType = OperationType.Move;
            Common.PopulateFilter(formCollection, filter);
            var results = filesService.SearchFileActions(filter);
            return PartialView(MVC.Reports.Views._MovesGrid, results);
        }

        public virtual ViewResult OffHours()
        {
            var model = new FilesModel(filter);
            model.FilesList = filesService.SearchOffHours(filter);
            ViewBag.Name = Resources.OffHoursTitle;
            return View(model);
        }

        [HttpPost]
        [ActionName("OffHours")]
        public virtual PartialViewResult FilterOffHours(FormCollection formCollection)
        {
            var model = new FilesModel(filter);
            Common.PopulateFilter(formCollection, filter);
            var results = filesService.SearchOffHours(filter);
            return PartialView(MVC.Reports.Views._OffHoursGrid, results);
        }

        #endregion
    }
}